package cn.hyh.core.service.impl;

import cn.hyh.core.dao.DicsMapper;
import cn.hyh.core.pojo.Dics;
import cn.hyh.core.service.ServiceInterface.DicService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @auther :hyh
 * @desc :
 * @date :2019/7/21
 */
@Service
public class DicServiceImpl implements DicService {

    @Resource
    private DicsMapper dicsMapper;

    @Override
    public Map<String, Object> getInitData() {
        Map<String, Object> map = new HashMap<>();
        String[] strArr = new String[]{"Label","Slideshow"};
        for (String s : strArr) {
            List<Dics> list = dicsMapper.selectByGroup(s);
            map.put(s.toLowerCase(), list);
        }
        return map;
    }

    @Override
    public Map<String, List<Dics>> selectGroup() {
        Map<String, List<Dics>> map = new HashMap<>();
        List<String> groupList=dicsMapper.getDistinceGroup();
        for (String s : groupList) {
            List<Dics> dics = dicsMapper.selectByGroup(s);
            map.put(s, dics);
        }
        return map;
    }

    /**
     *  初始化音乐数据
     * @return
     */
    @Override
    public Map<String, Object> initMusic() {
        List<Dics> list = dicsMapper.selectByGroup("Music");
        Map<String, Object> map = new HashMap<>();
         list.stream().forEach(  item ->{
             map.put(item.getName(), item.getValue());
         });
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("music", map);
        List<Dics> avatarList = dicsMapper.selectByGroup("Avatar");
        resultMap.put("avatar", avatarList.get(0));
        return resultMap;
    }

    /**
     * 增加天数
     */
    @Override
    public void addRuntimeDays() {
        List<Dics> list = dicsMapper.selectByGroup("Runtime");
        Dics dics = list.get(0);
        dics.setValue((Integer.parseInt(dics.getValue()) + 1)+"");
        dicsMapper.updateById(dics);
    }
}
